package com.kaiyidiannao.activity.daydaycoupon;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.kaiyidiannao.common.BaseActionBarActivity;
import com.kaiyidiannao.main.R;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created by Administrator on 14-4-2.
 * 第一个版本的分类，已经去掉了
 */
public class DdcCategoryActivity extends BaseActionBarActivity {
    private ArrayAdapter<String> menuAdapter;
    private ArrayAdapter<String> submenuAdapter;
    private ArrayList<String> menuData = new ArrayList<String>();
    private ArrayList<String> subMneuData = new ArrayList<String>();
    private String[][] subMenuAllData;
    private ListView menuListView, submenuListView;
    private int curBigType = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.daydaycoupon_category_activity);

        initMenuData();

        // 一级列表
        menuAdapter = new ArrayAdapter<String>(getApplicationContext(),
                R.layout.common_simple_list_item_1, android.R.id.text1, menuData);
        menuListView = (ListView) findViewById(R.id.daydaycoupon_type1);
        menuListView.setAdapter(menuAdapter);
        menuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                curBigType = position;
                subMneuData.clear();
                subMneuData.addAll(Arrays.asList(subMenuAllData[position]));
                submenuAdapter.notifyDataSetChanged();
            }
        });

        // 二级列表
        subMneuData.clear();
        subMneuData.addAll(Arrays.asList(subMenuAllData[0]));
        submenuAdapter = new ArrayAdapter<String>(getApplicationContext(),
                R.layout.common_simple_list_item_1, android.R.id.text1, subMneuData);
        submenuListView = (ListView) findViewById(R.id.daydaycoupon_type2);
        submenuListView.setAdapter(submenuAdapter);
        submenuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                String slectCatagory = subMenuAllData[curBigType][position];
                intent.putExtra("result", slectCatagory);
                setResult(RESULT_OK, intent); // 标识码，用来区分是否是程序正常返回数据，如物理键返回，接收数据就为null
                finish(); // 接收本Activity并从堆栈中移除
            }
        });
    }

    private void initMenuData() {
        menuData.add("分类1");
        menuData.add("分类2");
        menuData.add("分类3");
        menuData.add("分类4");
        menuData.add("分类5");
        menuData.add("分类6");
        menuData.add("分类7");

        subMenuAllData = new String[menuData.size()][];
        for (int i = 0; i < subMenuAllData.length; ++i) {
            subMenuAllData[i] = new String[10];
            for (int j = 0; j < subMenuAllData[i].length; ++j) {
                subMenuAllData[i][j] = "二级分类" + i + "-"+ j;
            }
        }
    }
}